package action;

import java.sql.ResultSet;

import java.sql.Statement;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import connection.MyConnection;

public class AdminLogin extends ActionSupport{
	
	private String user;
	private String pass;
	private String DBName;
	private String DBPass;
	boolean myFlag;

	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}



	@Override
	public String execute() throws Exception
	{
		MyConnection mc=new MyConnection();
		mc.connect();
		
		Map map = ActionContext.getContext().getSession();
		try 
		{
			
			Statement st = mc.con.createStatement();
			ResultSet rs = st.executeQuery("SELECT * FROM adminlogin");
			
			while(rs.next())
			{
				DBName=rs.getString(2);
				DBPass=rs.getString(3);
			}
			if(user.equals(DBName) && pass.equals(DBPass))
			{
				map.put("userName", user);
				myFlag = true ;
			}
			else{
				myFlag = false;
			}
		} catch (Exception e) 
		{
			e.printStackTrace();
			
		}
		if(myFlag==true)
			return "success";
		
		else
			return "error";
	}

}
